/*
 * Copyright (C) 2012  E-dance Studio Harbin Institute of Technology 
 * Project:campusmobile
 * Author: 初楷博
 * Create Date: 2012-5-23下午02:21:34
 */
package hit.edance.campusmobile.chat.model;

import hit.edance.campusmobile.chat.R;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

/**   
 * 聊天界面软键盘弹出调整Layout
 * 
 * @Project campusmobile
 * @Package hit.edance.campusmobile.chat.model
 * @Class ActivityChattingResizeLayout
 * @Date 2012-5-23 下午02:21:34
 * @author 初楷博
 * @version 1.0
 * @since 1.0
 */
public class ActivityChattingResizeLayout extends LinearLayout{

	//定义默认的软键盘最小高度，这是为了避免onSizeChanged在某些下特殊情况下出现的问题。
	private static final int SOFTKEYPAD_MIN_HEIGHT = 50;
	private Handler uiHandler = new Handler();
	
	public ActivityChattingResizeLayout(Context context) {
		super(context);
	}

	public ActivityChattingResizeLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected void onSizeChanged(int w, final int h, int oldw, final int oldh) {
		super.onSizeChanged(w, h, oldw, oldh);

		uiHandler.post(new Runnable() {

			public void run() {
				if (oldh - h > SOFTKEYPAD_MIN_HEIGHT)
					// 设置为View.GONE不占空间
					findViewById(R.id.talk_panel).setVisibility(View.GONE);
				else
					findViewById(R.id.talk_panel).setVisibility(View.VISIBLE);
			}
		});
	}

	@Override
	protected void onLayout(boolean changed, int l, int t, int r, int b) {
		super.onLayout(changed, l, t, r, b);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);

	}

}
